import json

from jsonpath import jsonpath

store = json.load(open('store.json'))

# the authors of all books in the store
print(jsonpath(store, '$.store.book[*].author'))

# all authors
print(jsonpath(store, '$..author'))

# all things in store, which are some books and a red bicycle.
print(jsonpath(store, '$.store.*'))

# the price of everything in the store.
print(jsonpath(store, '$.store..price'))

# the third book
print(jsonpath(store, '$..book[2]'))

# the last book in order.
print(jsonpath(store, '$..book[(@.length-1)]'))

# the first two books
print(jsonpath(store, '$..book[:2]'))

# filter all books with isbn number
print(jsonpath(store, '$..book[?(@.isbn)]'))

# filter all books without isbn number
print(jsonpath(store, '$..book[?(!@.isbn)]'))

# filter all books cheapier than 10
print(jsonpath(store, '$..book[?(@.price<10)]'))

# All members of JSON structure.
print(jsonpath(store, '$..*'))

# filter a book which category is fiction and author is J. R. R. Tolkien
print(jsonpath(store, '$..book[?(@.category=="fiction" && @.author=="J. R. R. Tolkien")]'))
print(jsonpath(store, '$..book[?(@.category=="fiction" and @.author=="J. R. R. Tolkien")]'))


